<template>
 <TreeSelect ret-attr="key" :multiple="multiple" v-model="selectVal" :treeData="OrgStruct" :placeholder='placeholder' strategy="SHOW_ALL"></TreeSelect>
</template>

<script>
import AppFrame from '../libs/app-frame';
import TreeSelect from '../components/tree-select';
export default {
    name: 'org-select',
    props: ['partnersId','value','multiple','placeholder','parentId'],
     model: {
        prop: 'value',
        event: 'updateVal'
    },
    components:{
        TreeSelect
    },
    data: function() {	
        return {
            selectVal:this.value,
            OrgStruct:[]
        }
    },
    created () {
        
    },

    watch: {
        partnersId:async function(curVal,oldVal){
            if(curVal!=oldVal){
                 await this.getData(curVal , this.parentId);
            }
        },
        selectVal:function(curVal,oldVal){
            this.setValue(curVal);
        },
         value:function(curVal){
            this.selectVal=curVal;
           
        },
    },
    methods: {
        init:function(){
            if(this.placeholder || this.placeholder==='') this.placeholder="请选择"; 
        },
        getData:async function(partnersId,parentId){
          let ret = await AppFrame.Http.Post("/manage-api/system/org-struct/getItemsByPartnersId",{partnersId:partnersId,parentId:parentId});
          if(ret && ret.Result==1){
              this.OrgStruct=ret.Data;
          }
        },
         setValue: function(val) {
            this.$emit("updateVal", val);
        },
    }
}
</script>

<style scoped>

</style>